package staff.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtils {
    private static final String DEFAULT_DATE_FORMAT = "dd.MM.yyyy";
    private static String dateFormat = DEFAULT_DATE_FORMAT;

    public static Date stringToDate(String dateString, String format) {
        try {
            return new SimpleDateFormat(format).parse(dateString);
        } catch (ParseException ex) {
            throw new IllegalArgumentException(ex);
        }
    }

    public static String datetoString(Date date, String format) {
        return date == null ? "" : new SimpleDateFormat(format).format(date);
    }

    public static String getDateFormat() {
        return dateFormat;
    }

    public static void setDateFormat(String dateFormat) {
        DateUtils.dateFormat = dateFormat;
    }

}
